﻿@model OT.Areas.Admin.Models.Countries
<div class="modal-content">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i></button>
        <h3 id="myModalLabel">Edit Country</h3>
    </div>
    <div>
        @Html.HiddenFor(model => model.CountryID, new { id = "HDFID" })
        <div class="modal-body">
            <div id="alert_modal"></div>
            <div class="form-horizontal" role="form">
                <div class="form-group">
                    <div class="col-lg-13" id="divMsgEdit">
                    </div>
                </div>
                <div class="form-group" id="divCountryCode">
                    <label class="col-lg-3 control-label">Country Code</label>
                    <div class="col-lg-5">
                        @Html.TextBoxFor(model => model.CountryCode, new { @maxlength = "10", @class = "form-control", @placeholder = "Enter Country Code" })
                        @Html.ValidationMessageFor(model => model.CountryCode)
                    </div>
                </div>
                <div class="form-group" id="divCountryName">
                    <label class="col-lg-3 control-label">Country Name</label>
                    <div class="col-lg-5">
                        @Html.TextBoxFor(model => model.CountryName, new { @maxlength = "50", @class = "form-control", @placeholder = "Enter Country Name" })
                        @Html.ValidationMessageFor(model => model.CountryName)
                    </div>
                </div>
            </div>
        </div>
        <div class="modal-footer">
            <button class="btn btn-default" type="submit" id="btnEdit"><i class="icon-cog"></i>Save</button>
            <button class="btn btn-default" data-dismiss="modal" aria-hidden="true"><i class="icon-off"></i>Cancel</button>
        </div>
    </div>
</div>
<script type="text/javascript">
    $("#btnEdit").click(function () {
        var CountryID = $("#HDFID").val();
        var CountryName = $("#CountryName").val();
        var CountryCode = $("#CountryCode").val();
        if (CountryName == '' || CountryCode == '') {
            showMsg('divMsgEdit', 'Please Enter Value in Required Field', 'danger');
            (CountryName == '') ? $('#divCountryName').addClass('has-error') : $('#divCountryName').removeClass('has-error');
            (CountryCode == '') ? $('#divCountryCode').addClass('has-error') : $('#divCountryCode').removeClass('has-error');
        }
        else {
            $.ajax({
                url: "/Admin/Country/Edit?CountryID=" + CountryID + "&CountryCode=" + CountryCode + "&CountryName=" + CountryName,
                type: "POST",
                success: function (result) {
                    if (result != "NotValid") {
                        $('#modalDiv').modal('hide');
                        bootstrap_alert.success('Sucessfully Updated Record.');
                        loadPage(1, 10, '');
                    }
                    else {
                        $('.modal-body #alert_modal').html('<div class="alert alert-warning"><a href="#" class="close" data-dismiss="alert">×</a><strong>' + "Error! " + '</strong><span>' + "not saved" + '</span></div>')
                    }
                },
                error: function (data) {
                }
            });
        }
        return false;
    });
</script>

